package persistencia;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import agenda.AgendaColaborativa;

public class PersistirAgenda {
	private static final String NOME_ARQUIVO = "agenda.dat";
	
	public static void salvar(AgendaColaborativa agenda) throws FileNotFoundException, IOException {
		ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(new File(NOME_ARQUIVO)));
		outputStream.writeObject(agenda);
		outputStream.close();
	}
	
	public static AgendaColaborativa carregar() throws FileNotFoundException, IOException, ClassNotFoundException {
		ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(new File(NOME_ARQUIVO)));
		AgendaColaborativa agenda = (AgendaColaborativa)inputStream.readObject();
		inputStream.close();
		return agenda;
	}
}
